/*
 * 闖ｴ諛茨ｿｽ隴鯉ｽ･�ｽ螢ｹ�ｽ2007陝ｷ�ｴ3隴幢ｿｽ隴鯉ｽ･
 */
package com.taylor.user.action;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;

import com.taylor.core.action.TaylorAction;

import com.taylor.core.bean.LessonInstructorBean;
import com.taylor.core.bean.Prefecture;
import com.taylor.core.bean.util.LessonEventUtil;
import com.taylor.core.dao.LessonEventDAO;
import com.taylor.core.db.DBSession;
import com.taylor.user.form.UF7LETopForm;

/**
 * <p>Title: TopPage</p>
 * <p>Description: Taylor</p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: </p>
 * @author Thao-TTP (FJN)
 * @version 1.0
 */
public class UF7LETopAction extends TaylorAction{
	
	static Logger log = Logger.getLogger(UF7LETopAction.class.getName());
	
	public ActionForward execute(ActionMapping mapping,ActionForm form,	
								 HttpServletRequest request,HttpServletResponse response) throws Exception {
		
		ActionErrors errors = new ActionErrors();
		
		try{
			
			DBSession.openSession(false); //conn.setAutoCommit(!isBeginTransaction);
			LessonEventDAO leDAO = new LessonEventDAO();
			
			//--------------------------------------------------
			//郢晢ｽｬ郢晢ｿｽ縺帷ｹ晢ｽｳ郢ｧ�､郢晏生ﾎｦ郢晏現縺檎ｹ晏干縺咏ｹ晢ｽｧ郢晢ｽｳ郢ｧ雋槫徐陟包ｿｽ
			UF7LETopForm 	frmUF7LETopForm	= new UF7LETopForm();
			List 			listInstructor 	= null;
			List 			listprefecturer = null;
			//List 			listEvent	 	= null;
			ArrayList 		arrInstructor 	= new ArrayList();
			//List 			listEvent	 	= null;
			ArrayList 		arrprefecturer 	= new ArrayList();
			ArrayList 		lismonth 	= new ArrayList();
			listInstructor = leDAO.selectInstructor_cond();
			listprefecturer = leDAO.selectPrefecture();
			
			
			//Use '.getInstance' methos to create oject of l逶ｻ蟄�Calendar.
	        Calendar cal = Calendar.getInstance();   
	        //get month and year now     
	        int month = cal.get(Calendar.MONTH);
	        int year  = cal.get(Calendar.YEAR);
	        
			for (int i = 0; i < listInstructor.size(); i++) {
				LessonInstructorBean lsBean = (LessonInstructorBean)listInstructor.get(i); 
				arrInstructor.add(new LabelValueBean(lsBean.getLi_family_name() + lsBean.getLi_first_name(),
													 lsBean.getLi_id().toString()));
		    }
			
			for (int i = 0; i < 4; i++) {
				
				month = month + 1;
	        	if(month > 12)
	        	{
	        		month = 1;
	        		year = year + 1;
	        	} 	
	        	String currentDate = year + "蟷ｴ" + month + "譛�";
	        	lismonth.add(new LabelValueBean(currentDate,
						currentDate));
		    }
			
			
			for (int i = 0; i < listprefecturer.size(); i++) {
				Prefecture lsBean = (Prefecture)listprefecturer.get(i); 
				arrprefecturer.add(new LabelValueBean(lsBean.getPc_name() ,
													 lsBean.getPc_id().toString()));
				//System.out.println(lsBean.getPc_name());
		    }
	        frmUF7LETopForm.setLstInstructor(arrInstructor);
	        frmUF7LETopForm.setLstMonth(lismonth);
	        frmUF7LETopForm.setLstPrefecture(arrprefecturer);
			//----------------------------------------------------------
			request.getSession(true).setAttribute("UF7LETopForm",frmUF7LETopForm);
	        //----------------------------------------------------------
		}catch (Exception e){
			log.error(e);
			e.printStackTrace();
			errors.add("errors.UF7.exception",new ActionError("errors.UF7.exception"));
			saveErrors(request, errors);
			return mapping.findForward(LessonEventUtil.LE_USER_ERR_PAGE);

		}finally{
			DBSession.closeSession();
		}
	
    		       
	
		return mapping.findForward("m-01");
    }
	
	
	
}
